﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quan_ly_thong_tin_he_thong
{
    public partial class MainForm : Form
    {
        public string taiKhoan;

        public MainForm()
        {
            InitializeComponent();
        }

        public MainForm(string Tk)
        {
            InitializeComponent();
            this.taiKhoan = Tk;
            taiKhoanToolStripStatusLabel2.Text = this.taiKhoan;
        }

        private void themPhongBanMenu_Click(object sender, EventArgs e)
        {
            ThemPhongBan f = new ThemPhongBan();
            f.ShowDialog();
        }

        private void xemThongTinPhongBanMenu_Click(object sender, EventArgs e)
        {
            XemThongTinPhongBan f = new XemThongTinPhongBan();
            f.ShowDialog();
        }

        private void chinhSuaPhongBanMenu_Click(object sender, EventArgs e)
        {
            XemSuaPhongBan f = new XemSuaPhongBan();
            f.ShowDialog();
        }

        private void ThemMoiNhaCungUngMenu_Click(object sender, EventArgs e)
        {
            Them_ChinhSuaNhaCungUng f = new Them_ChinhSuaNhaCungUng();
            f.ShowDialog();
        }

        private void thêmMớiNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemNhanVien f = new ThemNhanVien();
            f.ShowDialog();
        }

        private void chỉnhSửaNhânViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XemSuaNhanVien f = new XemSuaNhanVien();
            f.ShowDialog();
        }

        private void chỉnhSửaChứcVụToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XemSuaChucVu f = new XemSuaChucVu();
            f.ShowDialog();
        }

        private void thêmMớiChứcVụToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemChucVu f = new ThemChucVu();
            f.ShowDialog();
        }

        private void chấtLiệuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChatLieu f = new ChatLieu();
            f.ShowDialog();
        }

        private void loạiSảnPhẩmToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoaiSanPham f = new LoaiSanPham();
            f.ShowDialog();
        }

        private void thôngTinSảnPhẩmToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThongTinSanPham f = new ThongTinSanPham();
            f.ShowDialog();
        }

        private void hóaĐơnToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            HoaDon f = new HoaDon();
            f.ShowDialog();
        }

        private void thoatMenu_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void doiMatKhauMenu_Click(object sender, EventArgs e)
        {
            DoiMatKhau f = new DoiMatKhau();
            f.ShowDialog();
        }

        private void thôngTinKháchHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThongTinKhachHang f = new ThongTinKhachHang();
            f.ShowDialog();
        }

        private void thêmMớiTinTứcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemTinTuc f = new ThemTinTuc(taiKhoan);
            f.ShowDialog();
        }

        private void phânQuyềnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PhanQuyen f = new PhanQuyen();
            f.ShowDialog();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            nhanVienMenu.Enabled = false;
            sảnPhẩmToolStripMenuItem.Enabled = false;
            kháchHàngToolStripMenuItem.Enabled = false;
            hóaĐơnToolStripMenuItem.Enabled = false;
            nhàCungỨngToolStripMenuItem.Enabled = false;
            đơnHàngToolStripMenuItem.Enabled = false;
            tinTứcToolStripMenuItem.Enabled = false;
            liênHệToolStripMenuItem.Enabled = false;
            gópÝToolStripMenuItem.Enabled = false;
            ThongKeToolStripMenuItem.Enabled = false;

            Config file = new Config(Application.StartupPath + "\\Config.ini");
            string connectionstring = file.ReadValue("server", "con");
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select * from NhanVien,ChucVu where NhanVien.MaSo_CV = ChucVu.MaSo_CV and TenDangNhap_NV = @TenDangNhap_NV";
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.Parameters.AddWithValue("@TenDangNhap_NV", taiKhoan);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                if ((bool)reader["NhanVien"] == true)
                    nhanVienMenu.Enabled = true;

                if ((bool)reader["SanPham"] == true)
                    sảnPhẩmToolStripMenuItem.Enabled = true;

                if ((bool)reader["KhachHang"] == true)
                    kháchHàngToolStripMenuItem.Enabled = true;

                if ((bool)reader["HoaDon"] == true)
                    hóaĐơnToolStripMenuItem.Enabled = true;

                if ((bool)reader["NhaCungUng"] == true)
                    nhàCungỨngToolStripMenuItem.Enabled = true;

                if ((bool)reader["DonHang"] == true)
                    đơnHàngToolStripMenuItem.Enabled = true;

                if ((bool)reader["TinTuc"] == true)
                    tinTứcToolStripMenuItem.Enabled = true;

                if ((bool)reader["LienHe"] == true)
                    liênHệToolStripMenuItem.Enabled = true;

                if ((bool)reader["GopY"] == true)
                    gópÝToolStripMenuItem.Enabled = true;

                if ((bool)reader["ThongKe"] == true)
                    ThongKeToolStripMenuItem.Enabled = true;
            }
            reader.Close();
            conn.Close();
        }

        private void thôngTinĐơnMuaHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Them_ChinhSuaDonMuaHang f = new Them_ChinhSuaDonMuaHang();
            f.ShowDialog();
        }

        private void xemThôngTinLiênHệToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LienHe f = new LienHe();
            f.ShowDialog();
        }

        private void xemThôngTinGópÝToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GopY f = new GopY();
            f.ShowDialog();
        }   

    }
}
